<template>
  <div>
    <el-form ref="form" :model="orderlist" label-width="80px">
      <el-form-item label="申请人">
        <el-input v-model="orderlist.username" :disabled="isDisabled" style="width: 540px"></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="orderlist.state" style="width: 540px">
          <el-option label="已完成" value="已完成"></el-option>
          <el-option label="已发货" value="已发货"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">更新</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { fetchById, update } from "@/api/order";
export default {
  data() {
    return {
      isDisabled: true,
      orderlist: {},
    };
  },
  created() {
    fetchById({
      id: this.$route.params.id,
    }).then((res) => {
      console.log(res);
      this.orderlist = res.data;
    });
  },
  methods: {
    onSubmit() {
      update(this.orderlist).then((res) => {
        if (res.data.modified > 0) {
          this.$message({
            message: "更新成功",
            type: "success",
          });
        } else {
          this.$message.error("更新失败");
        }
        this.$router.push("/order/list");
      });
    },
    onCancel() {
      this.$router.push("/order/list");
    },
  },
};
</script>

<style scoped>
</style>



